home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15164 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: news.nynexst.com!rcn
  2. From: rcn@east (Ramesh Nagabushnam)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How do you reset a file?
  5. Date: 3 Apr 1996 23:35:08 GMT
  6. Organization: NYNEX Science & Technology, Inc
  7. Message-ID: <4jv1vc$ha1@news.nynexst.com>
  8. References: <3162b143.399039@news.airmail.net>
  9. NNTP-Posting-Host: east.nynexst.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Elizabeth Cunningham (liz@iadfw.net) wrote:
  13. : This might be a stupid question, but I couldn't find the answer in
  14. : either of the C++ books I have.  How do you reset an fstream object
  15. : back to the beginning of the file? 
  16.  
  17. Your question could be interpreted >= 2 ways
  18.  
  19. 1) You just want to move the file pointer:
  20.  
  21.    fstream fobj(..);
  22.  
  23.    fobj.seekpos(0,mode);  // see man filebuf
  24.  
  25. 2) You wish to truncate the file:
  26.  
  27.    fstream fobj(..);
  28.  
  29.    ftruncate(fobj.fd(),0);  // see man ftruncate(), man filebuf
  30.  
  31. -r
  32. ____________________________________________________
  33.   Ramesh Nagabushnam,           (o) (914) 644-2711 
  34.   rcn@nynexst.com               (h) (203) 967-1129
  35.